﻿using System;
using System.Web;

namespace msBsc.WebUi.Custom
{
    public partial class wfRegMailFill : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (this.strAction == "REGIST_STEP1")
            {
                if (this.GetParamHtValue("EMAIL") != string.Empty && this.GetParamHtValue("VALIDATE_CDE") != string.Empty)
                {
                    if (this.GetParamHtValue("VALIDATE_CDE") != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
                    {
                        this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                        this.Alert("验证码错误或已过期，请重新录入！");
                        return;
                    }
                    using (Epm.AppLogic.Framework.CDbAccess oCDbAccess = new Epm.AppLogic.Framework.CDbAccess())
                    {
                        System.Data.DataSet ds = oCDbAccess.QueryBySQL("SELECT TOP 1 E_MAIL FROM SYS_USER WHERE E_MAIL='" + this.GetParamHtValue("EMAIL") + "'");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                            this.Alert("您输入的邮箱地址已被注册，请重新录入！");
                            return;
                        }
                    }

                    string strcontent = "";
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "Template\\registmailtmp.htm", System.Text.Encoding.Default))
                    {
                        strcontent = sr.ReadToEnd();
                    }
                    msBsc.AppLogic.Cfg.DesCry ooo=new AppLogic.Cfg.DesCry();
                    string strurl = msBsc.AppLogic.Cfg.DesCry.encMe(this.GetParamHtValue("EMAIL") + "," + DateTime.Now.ToString(), "rmdes");
                    strurl = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.httpUrl + "c_RegUserInfoFill.htm?KEY=" + strurl;

                    strcontent = strcontent.Replace("{REGISTER_MAIL_USER_NME}", this.GetParamHtValue("EMAIL").Split('@')[0]).Replace("{REGISTER_MAIL_URL}", strurl);
                    msBsc.SvRef.SendEMail oSendEMail = new SvRef.SendEMail();
                    oSendEMail.SendEmailTo(this.GetParamHtValue("EMAIL").Split('@')[0], this.GetParamHtValue("EMAIL"), "好品济宁商城的注册申请确认！", strcontent);
                    //this.ExecJScript("debugger;");
                    this.ExecJScript("LS.set('CURR_REG_MAIL','" + this.GetParamHtValue("EMAIL") + "');");
                    this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "','STEP1');");
                    this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "_RDT','"+DateTime.Now.ToString()+"');");
                    this.ExecJScript("window.location.href = '/c_RegMailSend.htm';");

                    SetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, null, "2");
                }
            } 
        }

    }
}